﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.CompilerServices;
using System.Diagnostics;

namespace CygwinPackageManager.Common
{
	public class PackageActionDALC
	{
		public IEnumerable<PackageAction> GetStatuses()
		{
			return Actions;
		}

		private static IEnumerable<PackageAction> _actions;
		private static IEnumerable<PackageAction> Actions
		{
			[MethodImpl(MethodImplOptions.Synchronized)]
			get
			{
				if (_actions == null)
					_actions = _GetActions();

				return _actions;
			}
		}

		[MethodImpl(MethodImplOptions.Synchronized)]
		private static IEnumerable<PackageAction> _GetActions()
		{
			string dependenciesActions = "DepActions";
			string packageActions = "PackActions";

			List<PackageAction> actions = new List<PackageAction>();

			foreach (PackageActionIndex actionIndex in Enum.GetValues(typeof(PackageActionIndex)))
			{
				string name = string.Empty;
				string group = string.Empty;
				string description = string.Empty;
				switch (actionIndex)
				{
					case PackageActionIndex.Unmark:
						name = "Unmark";
						group = packageActions;
						break;
					case PackageActionIndex.Install:
						name = "Mark for Installation";
						group = packageActions;
						break;
					case PackageActionIndex.Remove:
						name = "Mark for Removal";
						group = packageActions;
						break;
					case PackageActionIndex.Update:
						name = "Mark for Update";
						group = packageActions;
						break;
					case PackageActionIndex.DependenciesInstall:
						name = "Mark Dependencies for Installation";
						group = dependenciesActions;
						break;
					case PackageActionIndex.DependenciesRemove:
						name = "Mark Dependencies for Removal";
						group = dependenciesActions;
						break;
					case PackageActionIndex.DependenciesUpdate:
						name = "Mark Dependencies for Update";
						group = dependenciesActions;
						break;
					default:
						throw new NotImplementedException();
				}

				actions.Add(new PackageAction()
				{
					Name = name,
					Group = group,
					Description = description,
					PackageActionID = (int)actionIndex,
				});
			}

			return actions;
		}
	}
}
